@extends('admin.public')

@section('content')
    <div class="col-md-12">
        <section class="panel panel-default">
            <header class="panel-heading bg-light no-border">
                <div class="clearfix">
                    @if(!empty($info['cover']))
                        <a href="#" class="pull-left b-3x m-r">
                            <img src="{{ $info['cover'] }}" alt="{{ $info->name }}"
                                 style="width: auto;height: 55px">
                        </a>
                    @endif
                    <div class="clear">
                        <div class="h3 m-t-xs m-b-xs">
                            {{ $info->name }}
                            @if( (bool)$info->status )
                                <i class="fa fa-circle text-success pull-right text-xs m-t-sm" title="模块信息开启"></i>
                            @else
                                <i class="fa fa-circle text-dark pull-right text-xs m-t-sm" title="模块信息关闭"></i>
                            @endif
                        </div>
                        <small class="text-muted">{{ $info->simpledescribe }}</small>
                        @if(!empty($info->file))
                            <small class="text-muted"><br>包含文件:
                                <a href="{{ $info->file }}">
                                    {{ basename($info->file) }}
                                </a>
                            </small>
                        @endif
                    </div>
                </div>
            </header>
        </section>
    </div>

    <div class="col-md-12">
        <form data-validate="parsley" method="post" enctype="multipart/form-data">
            <input type="hidden" name="id" value="{{ $info->id }}">
            {!! csrf_field() !!}
            <section class="panel panel-default">
                <header class="panel-heading">
                    {{ $chunk->name }} {{ $frame['title'] }}
                    <a href="{{ route('admin.info.info',$chunk->id) }}"
                       class="btn btn-xs btn-default pull-right">信息列表</a>
                </header>
                <div class="panel-body">
                    <p class="text-muted">
                        如需设置模块信息模版页面,请前往文件夹:<span
                                class="text-info">{{ pathinfo(config('app.info_theme'))['dirname'] }}</span>,按指定格式(<span
                                class="text-info">{{ pathinfo(config('app.info_theme'))['basename'] }}</span>)添加模版文件!
                    </p>
                    <div class="form-group">
                        <label>信息图片</label>
                        <input id="kv-explorer" type="file" multiple name="image">
                    </div>
                    <div class="form-group pull-in clearfix">
                        <div class="col-md-8">
                            <label>信息标题</label>
                            <input type="text" class="form-control parsley-validated" data-required="true" name="name"
                                   value="{{ $info->name }}">
                        </div>
                        <div class="col-md-4">
                            <label>信息排序</label>
                            <div class="clearfix"></div>
                            {{--<input class="slider slider-horizontal form-control" type="text" value="{{ $info->xindex }}"--}}
                            {{--data-slider-min="1" data-slider-max="100" data-slider-step="1"--}}
                            {{--data-slider-value="{{ $info->xindex }}"--}}
                            {{--data-slider-orientation="horizontal" name="xindex">--}}
                            <input type="number" class="form-control" name="xindex" value="{{ $info->xindex }}">
                        </div>
                    </div>
                    <div class="form-group pull-in clearfix">
                        <div class="col-md-8">
                            <label>信息模版</label>
                            <div class="clearfix"></div>
                            <select style="width:100%" class="chosen-select" name="theme">
                                @foreach( $themes as $theme)
                                    <option value="{{ $theme }}" {{ $theme==$info->theme?'selected':'' }}>{{ $theme }}</option>
                                @endforeach
                            </select>
                        </div>
                        <div class="col-md-4">
                            <label>信息浏览量</label>
                            <div class="input-group m-b">
                                <input type="text" class="form-control parsley-validated" data-required="true"
                                       value="{{ $info->page_view }}"
                                       name="page_view">
                                <span class="input-group-addon">次</span>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label>信息分类</label>
                        <div class="clearfix"></div>
                        <input type="hidden" name="sort" value="">
                        <select style="width:100%" multiple class="chosen-select srcsort">
                            @if( !empty($sorts) )
                                @foreach( $sorts as $sortlv1 )
                                    <option value="{{ $sortlv1['id'] }}"
                                            {{ array_search($sortlv1['id'],$info['sorts'])!==false?'selected':'' }}>
                                        {{ $sortlv1['name'] }}
                                    </option>
                                    @if( !empty($sortlv1['children']) )
                                        @foreach( $sortlv1['children'] as $sortlv2 )
                                            <option style="text-indent: 20px"
                                                    {{ array_search($sortlv2['id'],$info['sorts'])!==false?'selected':'' }}
                                                    value="{{ $sortlv2['id'] }}">
                                                {{ $sortlv2['name'] }}
                                            </option>
                                            @if( !empty($sortlv2['children']) )
                                                @foreach( $sortlv2['children'] as $sortlv3 )
                                                    <option style="text-indent: 40px"
                                                            value="{{ $sortlv3['id'] }}"
                                                            {{ array_search($sortlv3['id'],$info['sorts'])!==false?'selected':'' }}>
                                                        {{ $sortlv3['name'] }}
                                                    </option>
                                                    @if( !empty($sortlv3['children']) )
                                                        @foreach( $sortlv3['children'] as $sortlv4 )
                                                            <option style="text-indent: 60px"
                                                                    {{ array_search($sortlv4['id'],$info['sorts'])!==false?'selected':'' }}
                                                                    value="{{ $sortlv4['id'] }}">
                                                                {{ $sortlv4['name'] }}
                                                            </option>
                                                            @if( !empty($sortlv4['children']) )
                                                                @foreach( $sortlv4['children'] as $sortlv5 )
                                                                    <option style="text-indent: 80px"
                                                                            {{ array_search($sortlv5['id'],$info['sorts'])!==false?'selected':'' }}
                                                                            value="{{ $sortlv5['id'] }}">
                                                                        {{ $sortlv5['name'] }}
                                                                    </option>
                                                                @endforeach
                                                            @endif
                                                        @endforeach
                                                    @endif
                                                @endforeach
                                            @endif
                                        @endforeach
                                    @endif
                                @endforeach
                            @endif
                        </select>
                    </div>
                    <div class="form-group">
                        <label>信息标签</label>
                        <div class="clearfix"></div>
                        <input name="tag" id="tagsinput_tag" class="tagsinput" type="text"
                               value="{{ $info->tag }}"/>
                    </div>
                    <div class="form-group">
                        <label>摘要信息</label>
                        <textarea class="form-control" name="simpledescribe"
                                  placeholder="企业信息摘要 (如未填写,则引用详细信息中的前部分信息)">{{ $info->simpledescribe }}</textarea>
                    </div>
                    <div class="form-group">
                        <label>详细信息</label>
                        <div id="describe" name="describe" type="text/plain" style="width: 100%;height: 300px;"></div>
                    </div>
                    <div class="panel-group m-b" id="accordion2">
                        @if($chunk->extends)
                            <div class="panel isin panel-default">
                                <div class="panel-heading">
                                    <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2"
                                       href="#collapseOne">
                                        拓展功能
                                    </a>
                                </div>
                                <div id="collapseOne" class="panel-collapse collapse">
                                    <div class="panel-body text-sm">
                                        @if(array_search('jump_url',$chunk->extends) !== false)
                                            <div class="form-group">
                                                <label>页面跳转</label>
                                                <input type="text" class="form-control parsley-validated"
                                                       name="jump_url"
                                                       data-required="true" value="{{ $info->jump_url }}">
                                            </div>
                                        @endif
                                        @if(array_search('price',$chunk->extends) !== false)
                                            <div class="form-group">
                                                <label>价格</label>
                                                <input type="text" class="form-control parsley-validated" name="price"
                                                       value="{{ $info->price }}">
                                            </div>
                                        @endif
                                        @if(array_search('original_price',$chunk->extends) !== false)
                                            <div class="form-group">
                                                <label>原价</label>
                                                <input type="text" class="form-control parsley-validated"
                                                       name="original_price"
                                                       value="{{ $info->original_price }}">
                                            </div>
                                        @endif
                                        @if(array_search('sale',$chunk->extends) !== false)
                                            <div class="form-group">
                                                <label>销量</label>
                                                <input type="text" class="form-control parsley-validated" name="sale"
                                                       value="{{ $info->sale }}">
                                            </div>
                                        @endif
                                        <div class="form-group pull-in clearfix">
                                            @if(array_search('set_time_out',$chunk->extends) !== false)
                                                <div class="col-md-6">
                                                    <label>定时显示</label>
                                                    <div class="clearfix"></div>
                                                    <input class="input-sm input-s datepicker-input form-control"
                                                           name="set_time_out"
                                                           size="16"
                                                           type="text" value="{{ $info->set_time_out }}"
                                                           data-date-format="yyyy-mm-dd">
                                                </div>
                                            @endif
                                            @if(array_search('file',$chunk->extends) !== false)
                                                <div class="col-md-6">
                                                    <label>文件上传</label>
                                                    <div class="clearfix"></div>
                                                    <input type="file" name="file" class="filestyle" data-icon="false"
                                                           data-classButton="btn btn-default"
                                                           name="web_qrcode"
                                                           data-classInput="form-control inline v-middle input-s">
                                                </div>
                                            @endif
                                        </div>
                                    </div>
                                </div>
                            </div>
                        @endif
                        @if(!empty($chunk->extend))
                            <div class="panel isin panel-default">
                                <div class="panel-heading">
                                    <a class="accordion-toggle collapsed" data-toggle="collapse"
                                       data-parent="#accordion2"
                                       href="#collapseTwo">
                                        拓展信息
                                    </a>
                                </div>
                                <div id="collapseTwo" class="panel-collapse collapse">
                                    <div class="panel-body text-sm">
                                        @foreach(array_chunk(explode(',',$chunk->extend),10)[0] as $key => $value)
                                            @php
                                                $extend = 'extend_'.($key+1);
                                            @endphp
                                            <div class="col-md-4">
                                                <label>{{ $value }}</label>
                                                <div class="clearfix"></div>
                                                <input type="text" class="form-control parsley-validated"
                                                       name="extend_{{ $key+1 }}" value="{{ $info->$extend }}">
                                            </div>
                                        @endforeach
                                    </div>
                                </div>
                            </div>
                        @endif
                        <div class="panel isin panel-default">
                            <div class="panel-heading">
                                <a class="accordion-toggle collapsed" data-toggle="collapse" data-parent="#accordion2"
                                   href="#collapseThree">
                                    信息状态
                                </a>
                            </div>
                            <div id="collapseThree" class="panel-collapse collapse">
                                <div class="panel-body text-sm">
                                    <div class="checkbox i-checks">
                                        <label>
                                            <input type="checkbox" name="status" {{ (bool)$info->status?'checked':'' }}
                                            class="parsley-validated"><i></i> 勾选此项,即开启此信息
                                        </label>
                                    </div>
                                    <div class="checkbox i-checks">
                                        <label>
                                            <input type="checkbox" name="is_new" {{ (bool)$info->is_new?'checked':'' }}
                                            class="parsley-validated"><i></i> 勾选此项,此信息即为最新信息
                                        </label>
                                    </div>
                                    <div class="checkbox i-checks">
                                        <label>
                                            <input type="checkbox" name="is_push"
                                                   {{ (bool)$info->is_push?'checked':'' }}
                                                   class="parsley-validated"><i></i> 勾选此项,此信息即为推荐信息
                                        </label>
                                    </div>
                                    <div class="checkbox i-checks">
                                        <label>
                                            <input type="checkbox" name="is_hot" {{ (bool)$info->is_hot?'checked':'' }}
                                            class="parsley-validated"><i></i> 勾选此项,此信息即为热门信息
                                        </label>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <footer class="panel-footer text-right bg-light lter">
                    <button type="submit" class="btn btn-success btn-s-xs gatherInfo">保存</button>
                </footer>
            </section>
        </form>
    </div>
@endsection

@section('css')
    <link rel="stylesheet" href="/public/theme/js/slider/slider.css" type="text/css"/>
    <link href="/public/fileinput/css/fileinput.css" media="all" rel="stylesheet" type="text/css"/>
    <link href="/public/fileinput/themes/explorer/theme.css" media="all" rel="stylesheet" type="text/css"/>
    <link rel="stylesheet" href="/public/theme/js/chosen/chosen.css" type="text/css"/>
    <link rel="stylesheet" href="/public/theme/js/datepicker/datepicker.css" type="text/css"/>

@endsection

@section('js')
    <!-- datepicker -->
    <script src="/public/theme/js/datepicker/bootstrap-datepicker.js"></script>

    <!-- parsley -->
    <script src="/public/theme/js/parsley/parsley.min.js"></script>
    <script src="/public/theme/js/parsley/parsley.extend.js"></script>
    <script type="text/javascript" src="/public/theme/js/jPlayer/jquery.jplayer.min.js"></script>
    <script type="text/javascript" src="/public/theme/js/jPlayer/add-on/jplayer.playlist.min.js"></script>
    <script type="text/javascript" src="/public/theme/js/jPlayer/demo.js"></script>

    <!-- Chosen -->
    <script src="/public/theme/js/chosen/chosen.jquery.min.js"></script>

    <!-- slider -->
    <script src="/public/theme/js/slider/bootstrap-slider.js"></script>

    <!-- uediter -->
    <script src="/public/laravel-u-editor/ueditor.config.js"></script>
    <script src="/public/laravel-u-editor/ueditor.all.min.js"></script>
    <script src="/public/laravel-u-editor/lang/zh-cn/zh-cn.js"></script>

    <!-- fileinput -->
    <script src="/public/fileinput/js/plugins/sortable.js" type="text/javascript"></script>
    <script src="/public/fileinput/js/fileinput.js" type="text/javascript"></script>
    <script src="/public/fileinput/js/locales/zh.js" type="text/javascript"></script>
    <script src="/public/fileinput/js/locales/es.js" type="text/javascript"></script>
    <script src="/public/fileinput/themes/explorer/theme.js" type="text/javascript"></script>

    <!-- tagsinput -->
    <script src="/public/theme/js/tagsinput/bootstrap-switch.js"></script>
    <script src="/public/theme/js/tagsinput/jquery.tagsinput.js"></script>
    <script src="/public/theme/js/tagsinput/form-component.js"></script>

    <!-- file input -->
    <script src="/public/theme/js/file-input/bootstrap-filestyle.min.js"></script>

    <script>
        $(document).ready(function () {
            $("#kv-explorer").fileinput({
                uploadUrl: '{{ route('admin.info.addimage',$chunk->path) }}',
                allowedFileExtensions: ['jpg', 'png', 'gif'],
                language: 'zh',
                browseOnZoneClick: true,
                maxFileCount: {{ config('app.maxFileCount') }},
                minFileCount:{{ config('app.minFileCount') }},
                uploadAsync: true,
                theme: 'explorer',
                overwriteInitial: false,
                initialPreviewAsData: true,
                initialPreview: [
                    @foreach($info->images as $image)
                        "{{ $image }}",
                    @endforeach
                ],
                initialPreviewConfig: [
                        @foreach($info->images as $id => $image)
                    {
                        caption: "{{ basename('./'.$image) }}",
                        size: {{ filesize('./'.$image) }},
                        width: "120px",
                        url: '{{ route('admin.info.delimage') }}',
                        key: {{ $id }}},
                    @endforeach
                ]
            });
            $('.kv-preview-thumb').each(function () {
                var image_id = $(this).find('.kv-file-remove').attr('data-key');
                $(this).append('<input type="hidden" name="images[]" value="' + image_id + '" />')
            });
            $("#kv-explorer").on("fileuploaded", function (event, data, previewId, index) {
                if (data.response.status) {
                    $('#' + previewId).attr('delete-id', data.response.image_id).append('<input type="hidden" name="images[]" value="' + data.response.image_id + '" />');
                }
            })
            $('#kv-explorer').on('filesuccessremove', function (event, id) {
                var d = true;
                //得到要删除的图片的id
                var deleteId = $('#' + id).attr('delete-id');
                $.post('{{ url('admin/info/delimage') }}', {'key': deleteId, 'type': 'image'}, function (data) {
                    eval(' d = ' + data);
                    if (d.status) {
                        $('#' + id).remove();
                    }
                });
                return false;
            });
        });
    </script>
    <script>
        $('.gatherInfo').click(function () {
            var need = '';
            $('a.search-choice-close').each(function () {
                var order = $(this).attr('data-option-array-index');
                var id = $('.srcsort').find('option:eq(' + order + ')').val();
                need += id + ',';
            })
            $('input[name="sort"]').val(need);
        });
    </script>
    <script>
        var ue = UE.getEditor('describe');
        ue.ready(function () {
            var content = {'data': {!! json_encode($info->describe) !!}}
            ue.setContent(content.data);
        })
    </script>
    <script>
        $('.isin:eq(0)').find('.collapse').addClass('in');
    </script>
@endsection
